TryAggregateRootCommandHandler.execute   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 8
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
1
import { CommandHandler, EventPublisher, ICommandHandler } from '@nestjs/cqrs';
2
import { TryAggregateRootCommand } from '../commands/try.aggregate-root.command';
3
import { Inject } from '@nestjs/common';
4
import { TRANSPORT_EVENT_BUS_PUBLISHER } from '../../../../src/constants/transport.event-bus.constants';
5
import { TestModel } from '../model/test.model';
6
7
@CommandHandler(TryAggregateRootCommand)
8
export class TryAggregateRootCommandHandler implements ICommandHandler<TryAggregateRootCommand> {
9
    constructor(
10
        @Inject(TRANSPORT_EVENT_BUS_PUBLISHER) private readonly publisher: EventPublisher
11
    ) {
12
    }
13
14
    async execute(command: TryAggregateRootCommand) {
15
        const {message} = command;
16
        const aggregator = this.publisher.mergeObjectContext(
17
            new TestModel()
18
        );
19
        aggregator.applyEvent(message);
20
        aggregator.commit();
21
    }
22
}
23